package com.ghsc.yigou.live.utils

import android.animation.Animator
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.content.Context
import android.view.View
import android.view.animation.*
import com.ghsc.yigou.live.R

/**
 * 项目：JingShortVideo
 * 包名：com.bbl.jyShortVideo.ui.video.live.view
 * 类名：AnimUtils
 * 创建时间：2022/12/19 17:03
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
object AnimUtils {
    /**
     * 获取礼物入场动画
     *
     * @return
     */
    fun getInAnimation(context: Context?): Animation? {
        return AnimationUtils.loadAnimation(context, R.anim.gift_in) as TranslateAnimation
    }

    /**
     * 获取礼物出场动画
     *
     * @return
     */
    fun getOutAnimation(context: Context?): AnimationSet? {
        return AnimationUtils.loadAnimation(context, R.anim.gift_out) as AnimationSet
    }
    private var lastAnimator: Animator? = null

    fun start(view: View?) {
        if (lastAnimator != null) {
            lastAnimator!!.removeAllListeners()
            lastAnimator!!.end()
            lastAnimator!!.cancel()
        }
        val animX = ObjectAnimator.ofFloat(view, "scaleX", 1.6f, 1.0f)
        val animY = ObjectAnimator.ofFloat(view, "scaleY", 1.6f, 1.0f)
        val animSet = AnimatorSet()
        lastAnimator = animSet
        animSet.duration = 400
        animSet.interpolator = OvershootInterpolator()
        animSet.playTogether(animX, animY)
        animSet.start()
    }
}